Newer
Older
CubeSolver / Code Stuff / old / mainV2.py
import twophase.solver as sv
import kociemba
import pygame
import sys
# cubestring = 'LLBUUFFFLBDDDRBFFRDLURFLRBRBLUUDUDRBURLRLBRBDLUFDBDUFF'
# solution = sv.solve(cubestring, 0, 2)
# print(solution)
# solution2 = kociemba.solve(cubestring)
# print(solution2, len(solution2))
#
# final_solution = []


# Initialize pygame
pygame.init()

# Define colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GRAY = (150, 150, 150)

# Set up the screen
screen_width, screen_height = 400, 300
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Simple GUI with Pygame")

# Create a font
font = pygame.font.SysFont(None, 40)


# Function to display text on the screen
def draw_text(text, x, y, color):
    text_surface = font.render(text, True, color)
    screen.blit(text_surface, (x, y))


# Function to check if a point is inside a rectangle
def is_mouse_over(pos, rect):
    return rect.left < pos[0] < rect.right and rect.top < pos[1] < rect.bottom


# Function to create a button
def draw_button(rect, color, text):
    pygame.draw.rect(screen, color, rect)
    draw_text(text, rect.x + 10, rect.y + 10, BLACK)


class Button:
    rect = pygame.Rect
    isPressed = False
    name = "1"

    def draw(self, screen):
        if self.isPressed:
            pygame.draw.rect(screen, (0, 255, 0), self.rect)
        else:
            pygame.draw.rect(screen, (0, 0, 0), self.rect)
        draw_text(self.name, self.rect.x + 10, self.rect.y + 10, (255, 255, 255))



# Main function for GUI
def main():
    # Initialize variables
    number_input = ""

    # setup gui
    buttons = []
    buttonPoss = [
        (130, 10, 50, 50),
        (130, 70, 50, 50),
        (130, 190, 50, 50),
        (130, 250, 50, 50),
        (10, 130, 50, 50),
        (70, 130, 50, 50),
        (190, 130, 50, 50),
        (250, 130, 50, 50),

    ]
    for i, pos in enumerate(buttonPoss):
        buttons.append(Button())
        buttons[i].rect = pygame.Rect(pos)
        buttons[i].name = str(i)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    print("Entered number:", number_input)
                    number_input = ""
                elif event.key == pygame.K_BACKSPACE:
                    number_input = number_input[:-1]
                else:
                    number_input += event.unicode
            elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                mouse_pos = pygame.mouse.get_pos()
                for button in buttons:
                    button.isPressed = False
                    if is_mouse_over(mouse_pos, button.rect):
                        button.isPressed = True
                # # Check if the left mouse button is clicked on the buttons
                # if is_mouse_over(mouse_pos, pygame.Rect(150, 150, 100, 50)):
                #     print("Button 1 clicked!")
                # elif is_mouse_over(mouse_pos, pygame.Rect(150, 220, 100, 50)):
                #     print("Button 2 clicked!")

        # Clear the screen
        screen.fill(WHITE)

        # Draw the input field
        pygame.draw.rect(screen, GRAY, pygame.Rect(100, 50, 200, 40))
        draw_text(number_input, 110, 60, BLACK)

        # Draw buttons
        for button in buttons:
            button.draw(screen)
        # draw_button(pygame.Rect(150, 150, 100, 50), BLACK, "Button 1")
        # draw_button(pygame.Rect(150, 220, 100, 50), BLACK, "Button 2")

        # Update the display
        pygame.display.flip()


if __name__ == "__main__":
    main()

# i = 0
# while True:
#     # woo if statement spam
#     if solution[i] == "1":
#         final_solution[-1] += "n"
#         i += 2
#     elif solution[i] == "3":
#         final_solution[-1] += "p"
#         i += 2
#     elif solution[i] == "2":
#         final_solution[-1] += "n"
#         final_solution.append(final_solution[-1])
#         i += 2
#     elif solution[i] == "(":
#         break
#     else:
#         final_solution.append(solution[i])
#         i += 1
#
# print(final_solution)